{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello python\n"
     ]
    }
   ],
   "source": [
    "print ('hello python') "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from sklearn import datasets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "class LinearRegression():\n",
    "    def __init__(self):\n",
    "        self.w = None\n",
    "\n",
    "    def fit(self, X, y):\n",
    "        X = np.insert(X, 0, 1, axis=1)\n",
    "        print (X.shape)        \n",
    "        X_ = np.linalg.inv(X.T.dot(X))\n",
    "        self.w = X_.dot(X.T).dot(y)\n",
    "        \n",
    "\n",
    "    def predict(self, X):\n",
    "        # Insert constant ones for bias weights\n",
    "        X = np.insert(X, 0, 1, axis=1)\n",
    "        y_pred = X.dot(self.w)\n",
    "        return y_pred\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def mean_squared_error(y_true, y_pred):\n",
    "    mse = np.mean(np.power(y_true - y_pred, 2))\n",
    "    return mse"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def main():\n",
    "    # Load the diabetes dataset\n",
    "    diabetes = datasets.load_diabetes()\n",
    "\n",
    "    # Use only one feature\n",
    "    X = diabetes.data[:, np.newaxis, 2]\n",
    "    print (X.shape)\n",
    "    # Split the data into training/testing sets\n",
    "    x_train, x_test = X[:-20], X[-20:]\n",
    "\n",
    "    # Split the targets into training/testing sets\n",
    "    y_train, y_test = diabetes.target[:-20], diabetes.target[-20:]\n",
    "\n",
    "    clf = LinearRegression()\n",
    "    clf.fit(x_train, y_train)\n",
    "    y_pred = clf.predict(x_test)\n",
    "\n",
    "    # Print the mean squared error\n",
    "    print (\"Mean Squared Error:\", mean_squared_error(y_test, y_pred))\n",
    "\n",
    "    # Plot the results\n",
    "    plt.scatter(x_test[:,0], y_test,  color='black')\n",
    "    plt.plot(x_test[:,0], y_pred, color='blue', linewidth=3)\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(442, 1)\n",
      "(422, 2)\n",
      "Mean Squared Error: 2548.07239873\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAhQAAAFkCAYAAAB4sKK5AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3Xt4ZFWd7//3l2C3iHQTULrlMCJ2khaP146ijAPiz0hC\nO14YBse0MwjMmdHj5WF6/B05zs9Rjv6O8wgqeOMcPV5xtGawUVF/kGgYFQWEmW5GEVsqCSAC0oJp\nuxscbun1+2NXoBKSdO3sVOqS9+t56nmotdeuWrW76Pr0WmuvFSklJEmSitiv0Q2QJEmtz0AhSZIK\nM1BIkqTCDBSSJKkwA4UkSSrMQCFJkgozUEiSpMIMFJIkqTADhSRJKsxAIUmSCssVKCLizRHxk4jY\nVXlcHREDVcc/HxF7Zzwum/EaKyPikxFxT0TsiYgtEXHYYn0gSZK09PL2UPwKOBvYAPQC/wJcGhFH\nV9W5HFgDrK08Bme8xgXAK4FTgOOBw4FLcrdckiQ1jSi6OVhE/Bb4v1NKn4+IzwOrU0p/MkfdVcDd\nwOtTSl+vlK0HtgMvTildV6gxkiSpIRY8hyIi9ouI1wNPAK6uOnRCROyIiF9ExIURcUjVsV5gf+CK\nqYKU0k3AbcCxC22LJElqrP3znhARzwKuAR4P7AFOroQCyIY7LgFuAdYB/wBcFhHHpqwrZC3wYEpp\n94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G0lm2T48qmCiFgPPLXynm2nnte80rtwF9Ov5yqy\nORdXz9Os55P9+fy62KdrLSmlh8i+g9XXKyrP57pe11TXrziR6d/X2eq8gjb9TudRx2s+TUTsBzyb\nZfadns0Cr3kt/J7PoY7XfJoFfc8bPVu1Mrv0MuDfgBcCLyEby/nSjDq/AF5T9byT7DavjWR3LLyu\n8nxNVZ0Lyf5VfALZJJargB82+vM2w2OB1/ydwG+BV1W+aN8ARoEVleNPB94NbCC7++bVwBjwL43+\nvA26xq8Dfg+cRnZnzacq1+/JleP/AHyxqv7TgD1kdx6sB94CPAj0VdU5luzupb+t1DkHuB94ZqM/\nbzM86nTN/57sx+wosoBcIrtl+hmN/rzN8Mh7zStlzyW7HfRfyeZYPRc4uuq43/Olv+aFv+cNvzCV\nD3Iw8I9k98DuJLv3+Akz6kwCp1U9fyNZkJic8XhPVZ2VwMfJuoj2AF8FDmv0522Gx0KueaXsHLLb\nR39PNuu6q+rYEcD3gbsrx2+qfLGf2OjP28Dr/BbgVrLba68BXlB17PPMCFtk64FsrdQfBf5iltc8\nhSzs/QfwU7JN9Rr+WZvlsdjXnGxn5Fsqx+8EvsWM29SX+2MB13y2v7tvnlHH7/kSXvPF+J67OZgk\nSSqsGW4blSRJLc5AIUmSCjNQSJKkwgwUkiSpMAOFJEkqzEAhSZIKM1BIkqTCDBSSJKkwA4UkSSrM\nQCFJkgozUEiSpML+fy+564z8lSAhAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x25273d31f28>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "main()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    " print (X.shape)\n",
    "        X = np.insert(X, 0, 1, axis=1)\n",
    "        print (X.shape)        \n",
    "        X_ = np.linalg.inv(X.T.dot(X))\n",
    "        self.w = X_.dot(X.T).dot(y)\n"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
